package by.brest.bspc.repository.utils;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.List;

import static by.brest.bspc.repository.Constants.CLASS_NUMBER;
import static by.brest.bspc.repository.Constants.DIRESPECT;
import static by.brest.bspc.repository.Constants.DISCIPLINE_NAME;
import static by.brest.bspc.repository.Constants.FACULTY;
import static by.brest.bspc.repository.Constants.GRADE_LIST;
import static by.brest.bspc.repository.Constants.GRADE_TYPE;
import static by.brest.bspc.repository.Constants.GROUP_NAME;
import static by.brest.bspc.repository.Constants.MARK;
import static by.brest.bspc.repository.Constants.RESPECT;
import static by.brest.bspc.repository.Constants.SEMESTER_NUMBER;
import static by.brest.bspc.repository.Constants.SPECIALTY;
import static by.brest.bspc.repository.Constants.SPECIALTY_CODE;
import static by.brest.bspc.repository.Constants.SPECIALTY_NAME;
import static by.brest.bspc.repository.Constants.STATUS;
import static by.brest.bspc.repository.Constants.ID;
import static by.brest.bspc.repository.Constants.STUDENT_NAME;
import static by.brest.bspc.repository.Constants.STUDY;
import static by.brest.bspc.repository.Constants.TEACHER_NAME;
import static by.brest.bspc.repository.utils.Constants.CLASS_NUMBER_TEST;
import static by.brest.bspc.repository.utils.Constants.COUNT_OBJECTS;
import static by.brest.bspc.repository.utils.Constants.DIRESPECT_TEST;
import static by.brest.bspc.repository.utils.Constants.DISCIPLINE_NAME_TEST;
import static by.brest.bspc.repository.utils.Constants.FACULTY_TEST;
import static by.brest.bspc.repository.utils.Constants.GRADE_TYPE_TEST;
import static by.brest.bspc.repository.utils.Constants.MARK_TEST;
import static by.brest.bspc.repository.utils.Constants.RESPECT_TEST;
import static by.brest.bspc.repository.utils.Constants.SEMESTER_NUMBER_TEST;
import static by.brest.bspc.repository.utils.Constants.SPECIALTY_CODE_TEST;
import static by.brest.bspc.repository.utils.Constants.SPECIALTY_NAME_TEST;
import static by.brest.bspc.repository.utils.Constants.STATUS_TEST;
import static by.brest.bspc.repository.utils.Constants.STUDENT_ID_TEST;
import static by.brest.bspc.repository.utils.Constants.STUDENT_NAME_TEST;
import static by.brest.bspc.repository.utils.Constants.STUDY_TEST;
import static by.brest.bspc.repository.utils.Constants.TEACHER_NAME_TEST;

/**
 * This class creates and initializes the various <code>DBObjects</code> for tests.
 *
 * @Date: 3/14/13 11:33 PM
 * @Author: frehty
 */
public abstract class DBObjectCreator {
    private static final Logger LOG = LoggerFactory.getLogger(DBObjectCreator.class);

    /**
     * Creates and initialized a new object of {@link com.mongodb.DBObject}
     *
     * @return <code>studentDBObject</code>
     */
    public static DBObject createStudentDBObject() {
        DBObject studentDBObject = new BasicDBObject();

        studentDBObject.put(ID, STUDENT_ID_TEST);
        studentDBObject.put(STUDENT_NAME, STUDENT_NAME_TEST);
        studentDBObject.put(STUDY, STUDY_TEST);
        studentDBObject.put(FACULTY, FACULTY_TEST);
        studentDBObject.put(SPECIALTY, createSpecialtyDBObject());
        studentDBObject.put(CLASS_NUMBER, CLASS_NUMBER_TEST);
        studentDBObject.put(GROUP_NAME, GRADE_TYPE_TEST);
        studentDBObject.put(GRADE_LIST, createGradeListDBObject());
        studentDBObject.put(STATUS, STATUS_TEST);

        LOG.debug(">> Created studentDBObject: " + studentDBObject);

        return studentDBObject;
    }

    /**
     * Creates and initialized a new object of {@link com.mongodb.DBObject}
     *
     * @return <code>specialtyDBObject</code>
     */
    private static DBObject createSpecialtyDBObject() {
        DBObject specialtyDBObject = new BasicDBObject();

        specialtyDBObject.put(SPECIALTY_NAME, SPECIALTY_NAME_TEST);
        specialtyDBObject.put(SPECIALTY_CODE, SPECIALTY_CODE_TEST);

        LOG.debug(">> Created specialtyDBObject: " + specialtyDBObject);

        return specialtyDBObject;
    }

    /**
     * Creates and initialized a new object of {@link com.mongodb.DBObject}
     *
     * @return <code>gradeListDBObject</code>
     */
    private static List<DBObject> createGradeListDBObject() {
        List<DBObject> gradeListDBObject = new LinkedList<>();

        for (int i = 0; i < COUNT_OBJECTS; i++) {
            DBObject grade = new BasicDBObject();

            grade.put(GRADE_TYPE, GRADE_TYPE_TEST);
            grade.put(SEMESTER_NUMBER, SEMESTER_NUMBER_TEST);
            grade.put(DISCIPLINE_NAME, DISCIPLINE_NAME_TEST + i);
            grade.put(TEACHER_NAME, TEACHER_NAME_TEST + i);
            grade.put(MARK, MARK_TEST);
            grade.put(RESPECT, RESPECT_TEST);
            grade.put(DIRESPECT, DIRESPECT_TEST);

            LOG.debug(">> Created grade: " + grade);

            gradeListDBObject.add(grade);
        }

        LOG.debug(">> Created gradeListDBObject: " + gradeListDBObject);

        return gradeListDBObject;
    }
}